const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
//今日日期
const formatTimedate = date => {
  const month = date.getMonth() + 1
  const day = date.getDate()
  return [month,day].map(formatNumber).join('-')
}
//今日星期
const formatTimeday = date => {
  const da = date.getDay()//获取当前星期X(0-6,0代表星期天)
  return da
}
//明天日期
const formatTimedatet = date => {
  const month = date.getMonth() + 1
  const day = date.getDate() + 1
  return [month, day].map(formatNumber).join('-')
}
//明天星期
const formatTimedayt = date => {
  const da = date.getDay()+ 1 //获取当前星期X(0-6,0代表星期天)
  return da
}

//点击事件
function buttonClicked(self) {
  self.setData({
    buttonClicked: true
  })
  setTimeout(function () {
    self.setData({
      buttonClicked: false
    })
  }, 500)
}
module.exports = {
  formatTime: formatTime,
  formatTimedate: formatTimedate,
  formatTimeday: formatTimeday,
  formatTimedatet: formatTimedatet,
  formatTimedayt: formatTimedayt,
  buttonClicked: buttonClicked
}
